/*
 * Copyright (C) 2011 Project R'yleh Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.Arkham;

import java.util.ArrayList;

public class Tester {
	public Party party = new Party();
	public ArrayList<String> ErrorLog;
	
	public Tester(){
		party = new Party();
		ErrorLog = new ArrayList<String>();

	}
	
	public void printErrors(){
		if(ErrorLog.size() == 0)
			System.out.println("No errors detected");
		else
			System.out.println("!!!!----ERRORS DETECTED----!!!!");
		while(ErrorLog.size() != 0){
			System.out.println(ErrorLog.get(0));
			ErrorLog.remove(0);
		}
	}
	
	public void TestingSuit(){
		initializeValues();
		BuyandSellItems();
		EquipingandUnequipingItems();
	}
	
	public void initializeValues(){
		if (party.inventory.size() != 0)
			ErrorLog.add("INITIALIZE VALUES: Inventory not initialized to zero.");
		if (party.inventory.getMoney() != 0)
			ErrorLog.add("INITIALIZE VALUES: Money not initialized to zero.");
	}
	
	public void BuyandSellItems(){
		party.inventory = new Inventory();
		
		party.inventory.gainItem(Armory.Pencil());
		if(party.inventory.size() != 1)
			ErrorLog.add("BUY & SELL ITEMS: 1st Pencil not added.");
		
		party.inventory.gainItem(Armory.Pencil());
		if(party.inventory.size() != 2)
			ErrorLog.add("BUY & SELL ITEMS: 2nd Pencil not added.");
		
		party.inventory.gainItem(Armory.Calculator());
		if(party.inventory.size() != 3)
		    ErrorLog.add("BUY & SELL ITEMS: Calculator not added.");

		if(!party.inventory.contains(Armory.Pencil()) || 
		   !party.inventory.contains(Armory.Calculator()))
			ErrorLog.add("BUY & SELL ITEMS: Search for existing.");

		if(party.inventory.contains(Armory.Eraser()))
			ErrorLog.add("BUY & SELL ITEMS: Search for NON-existing.");

		party.inventory.setMoney(100);
		party.inventory.purchaseItem(Armory.ExtraCreditHomework());  //price is 10
		if(party.inventory.getMoney() != 90)
			ErrorLog.add("BUY & SELL ITEMS: Purchase money not subtracted.");

		if(party.inventory.size() != 4 && 
		   !party.inventory.contains(Armory.ExtraCreditHomework()))
			ErrorLog.add("BUY & SELL ITEMS: Homeowork not added.");
		
		party.inventory.sellItem(2); //selling calculator for 2
		if(party.inventory.getMoney() != 92)
			ErrorLog.add("BUY & SELL ITEMS: Sell money not added.");
		
		if(party.inventory.size() != 3 && 
		   party.inventory.contains(Armory.Calculator()))
			ErrorLog.add("BUY & SELL ITEMS: Calculator not sold.");
		
		party.inventory.useItem(2); //using calculator
		if(party.inventory.size() != 2 && 
		  !party.inventory.contains(Armory.Calculator()))
			ErrorLog.add("BUY & SELL ITEMS: Calculator not used.");		
		
		if(party.inventory.useItem(0)) //using pencil
			ErrorLog.add("BUY & SELL ITEMS: used pencil, not allowed.");
		
		if(party.inventory.size() != 2)
			ErrorLog.add("BUY & SELL ITEMS: Pencil subrtacted from inventory.");	
	}

	public void EquipingandUnequipingItems(){
		party.inventory = new Inventory();
		Character newChar = new Character();
		
		newChar.changeName("Charles");
		party.characters[0] = newChar;
		newChar = new Character();
		newChar.changeName("Mike");
		party.characters[1] = newChar;
		
		if( party.characters[0].getName() == party.characters[1].getName() )
			ErrorLog.add("EQUIPING & UNEQUIPING: Like named characters.");
		
		party.inventory.gainItem(Armory.Pencil());
		party.inventory.gainItem(Armory.Pencil());
		party.equip(0, Constants.R_HAND, party.characters[0]);
		party.equip(1, Constants.R_HAND, party.characters[1]);
		
		if ( !party.inventory.isEquipped(0) || !party.inventory.isEquipped(1) )
			ErrorLog.add("EQUIPING & UNEQUIPING: Items did not equip.");
		
		if ( party.inventory.whoEquipped(0) == party.inventory.whoEquipped(1) )
			ErrorLog.add("EQUIPING & UNEQUIPING: Pencils linked somehow.");
		
		if( party.inventory.whoEquipped(0) != "Charles" ||
			party.inventory.whoEquipped(1) != "Mike" )
			ErrorLog.add("EQUIPING & UNEQUIPING: equiping status not updating.");
		
		party.unequip(Constants.R_HAND, party.characters[0]);
		if ( party.characters[0].whatEquipped(Constants.R_HAND) != Armory.None)
			ErrorLog.add("EQUIPING & UNEQUIPING: unequiping status not updating.");
	}

}
